package cn.aspect;

import cn.constant.Messages;
import cn.entity.User;
import cn.util.AspectUtils;
import cn.util.AuthUtils;
import cn.web.model.ApiResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author m on 2023/1/31
 * Description:
 */
@Component
@Aspect
public class TagAspect {

    @Pointcut("execution(* cn.web.controller.TagApiController.deleteTag(..)) ||" +
            " execution(* cn.web.controller.TagApiController.findTags(..)) || " +
            "execution(* cn.web.controller.TagApiController.approveTag(..))")
    public void admin(){}


    @Around("admin()")
    public ApiResult aroundAdmin(ProceedingJoinPoint point) throws Throwable {
        String token = AspectUtils.getToken(point);
        if(AuthUtils.illegalUser(token,new int[]{User.TYPE_ADMIN})){
            return new ApiResult(false, Messages.NO_PERMISSION.toString(),null);
        }
        return (ApiResult) point.proceed();
    }
}
